<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>Hugo博客图形化写作工具 - L_B__</title><meta name="referrer" content="no-referrer">
<meta name="description" content="Hugo博客图形化写作工具"><meta property="og:title" content="Hugo博客图形化写作工具" />
<meta property="og:description" content="Hugo博客图形化写作工具" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://acking-you.github.io/posts/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/" /><meta property="og:image" content="https://acking-you.github.io/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-02-12T00:00:00+00:00" />
<meta property="article:modified_time" content="2022-02-12T00:00:00+00:00" />

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://acking-you.github.io/logo.png"/>

<meta name="twitter:title" content="Hugo博客图形化写作工具"/>
<meta name="twitter:description" content="Hugo博客图形化写作工具"/>
<meta name="application-name" content="FeelIt">
<meta name="apple-mobile-web-app-title" content="FeelIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="canonical" href="https://acking-you.github.io/posts/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/" /><link rel="prev" href="https://acking-you.github.io/posts/leetcode%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%981020%E9%A3%9E%E5%9C%B0%E7%9A%84%E6%95%B0%E9%87%8F/" /><link rel="next" href="https://acking-you.github.io/posts/%E7%89%9B%E5%AE%A2-wyh%E7%9A%84%E7%89%A9%E5%93%81%E9%80%9A%E8%BF%87%E9%AA%8C%E8%AF%81%E5%BE%97%E5%87%BA%E4%BA%8C%E5%88%86%E7%9A%84%E6%90%9C%E7%B4%A2%E5%8C%BA%E9%97%B4/" /><link rel="stylesheet" href="/css/page.min.css"><link rel="stylesheet" href="/css/home.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "Hugo博客图形化写作工具",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/acking-you.github.io\/posts\/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7\/"
        },"genre": "posts","keywords": "Hugo博客图形化写作工具","wordcount":  2124 ,
        "url": "https:\/\/acking-you.github.io\/posts\/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7\/","datePublished": "2022-02-12T00:00:00+00:00","dateModified": "2022-02-12T00:00:00+00:00","publisher": {
            "@type": "Organization",
            "name": "作者"},"author": {
                "@type": "Person",
                "name": "作者"
            },"description": "Hugo博客图形化写作工具"
    }
    </script></head><body data-header-desktop="auto" data-header-mobile="auto"><script>(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="L_B__">L_B__</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="#" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="L_B__">L_B__</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="#" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="#" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><div class="menu-item"><a href="javascript:void(0);" class="theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div></div>
    </div>
</header><div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single" data-toc="disable"><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/img_convert/5bc78a387fa03b5039b9bca28aea1b14.png#pic_center"
        data-srcset="https://img-blog.csdnimg.cn/img_convert/5bc78a387fa03b5039b9bca28aea1b14.png#pic_center, https://img-blog.csdnimg.cn/img_convert/5bc78a387fa03b5039b9bca28aea1b14.png#pic_center 1.5x, https://img-blog.csdnimg.cn/img_convert/5bc78a387fa03b5039b9bca28aea1b14.png#pic_center 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/img_convert/5bc78a387fa03b5039b9bca28aea1b14.png#pic_center"
        title="Hugo博客图形化写作工具" /></div><div class="single-card" data-image="true"><h2 class="single-title animated flipInX">Hugo博客图形化写作工具</h2><div class="post-meta">
                <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>作者</a></span>&nbsp;<span class="post-category">出版于  <a href="/categories/c++%E5%AE%9E%E6%88%98/"><i class="far fa-folder fa-fw"></i>C++实战</a></span></div>
                <div class="post-meta-line"><span><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-02-12">2022-02-12</time></span>&nbsp;<span><i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 2124 字</span>&nbsp;
                    <span><i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 5 分钟</span>&nbsp;</div>
            </div>
            
            <hr><div class="details toc" id="toc-static"  data-kept="">
                    <div class="details-summary toc-title">
                        <span>目录</span>
                        <span><i class="details-icon fas fa-angle-right"></i></span>
                    </div>
                    <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#软件使用">软件使用</a></li>
    <li><a href="#项目介绍">项目介绍</a></li>
    <li><a href="#qtrun-c-源代码">QtRun C++ 源代码</a></li>
  </ul>
</nav></div>
                </div><div class="content" id="content"><h2 id="软件使用">软件使用</h2>
<p><a href="https://www.bilibili.com/video/BV11S4y1G7SW" target="_blank" rel="noopener noreffer">视频教程</a></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s2.loli.net/2022/02/12/dklYO6E5oVtMT8b.png"
        data-srcset="https://s2.loli.net/2022/02/12/dklYO6E5oVtMT8b.png, https://s2.loli.net/2022/02/12/dklYO6E5oVtMT8b.png 1.5x, https://s2.loli.net/2022/02/12/dklYO6E5oVtMT8b.png 2x"
        data-sizes="auto"
        alt="https://s2.loli.net/2022/02/12/dklYO6E5oVtMT8b.png"
        title="image-20220212141742071" /></p>
<h2 id="项目介绍">项目介绍</h2>
<p><a href="https://github.com/ACking-you/AutoHugoWrite" target="_blank" rel="noopener noreffer">项目所在地</a></p>
<blockquote>
<p>温馨提示：如果本地还未搭建 hugo 博客，可以使用我的另一个 <a href="https://github.com/ACking-you/AutoHugoSetup" target="_blank" rel="noopener noreffer">hugo 博客自动搭建工具</a></p>
</blockquote>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s2.loli.net/2022/02/09/yJY4VAImClOKcqE.png"
        data-srcset="https://s2.loli.net/2022/02/09/yJY4VAImClOKcqE.png, https://s2.loli.net/2022/02/09/yJY4VAImClOKcqE.png 1.5x, https://s2.loli.net/2022/02/09/yJY4VAImClOKcqE.png 2x"
        data-sizes="auto"
        alt="https://s2.loli.net/2022/02/09/yJY4VAImClOKcqE.png"
        title="AutoHugoWrite" /></p>
<ul>
<li>
<p><strong>QtRun</strong>：</p>
<ul>
<li>
<p><strong>介绍</strong>：一个用纯 C++ 写的命令行工具。</p>
</li>
<li>
<p><strong>主要作用</strong>：根据提供的 hugo 博客本地地址进行命令行式的自动化写作，会把每一篇文章的图片、分类、标题等内容自动化完成。</p>
</li>
<li>
<p><strong>构建方式</strong>：确保生成 exe 文件的目录下含有以下文件，且确保编译器支持 C++17。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell">BlogPath.txt <span class="c1">#提供本地hugo博客路径</span>
categories.txt <span class="c1">#提供可供选择的分类(没有也没关系)</span>
initImg.txt		<span class="c1">#提供可选择的图片</span>
mob.txt			<span class="c1">#提供用于生成的模板</span>
ed_Path.txt		<span class="c1">#提供打开的编辑器路径(没有也没关系)</span>
</code></pre></div></li>
<li>
<p><strong>使用方式</strong>：可查看源码得到更详尽的解答</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"> QtRun <span class="o">[</span>title name<span class="o">]</span> <span class="o">[</span>category name<span class="o">]</span>
 Qtrun <span class="o">[</span>-op<span class="o">]</span>
</code></pre></div></li>
</ul>
</li>
<li>
<p><strong>QtRunBlog</strong>：</p>
<ul>
<li><strong>介绍</strong>：使用 Qt+cmake 搭建的图形化 hugo 自动化工具，写作的相关部分都是调用的 QtRun ，所以运行时 QtRun 的配置文件和 QtRun 都必须在它的 exe 目录之下。而其他其他部分调用的 git 命令行，所以需要本地有 git 工具。</li>
<li><strong>主要作用</strong>：提供图形化的 hugo 写作体验。</li>
<li><strong>构建方式</strong>：本地需要 Qt6 环境，选择本项目目录便可完成构建。</li>
</ul>
</li>
</ul>
<h2 id="qtrun-c-源代码">QtRun C++ 源代码</h2>
<blockquote>
<p>实现了自动化命令行写作，QtRunBlog图形化界面调用的就是它的命令行</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">//
</span><span class="c1">// Created by Alone on 2022-1-24.
</span><span class="c1">//
</span><span class="c1">//TODO aaaaaaa得出感悟：1.数据较为复杂的情况下尽量不要使用全局变量 2.在构造函数初始化的时候千万不要直接new空间给它，记得随时随地nullptr
</span><span class="c1"></span><span class="cp">#include</span> <span class="cpf">&lt;fstream&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;string&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;sys/stat.h&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;unistd.h&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;windows.h&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;vector&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;unordered_map&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;ctime&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;filesystem&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;random&gt;</span><span class="cp">
</span><span class="cp"></span>
<span class="cp">#define IMGS_PATH &#34;./initImg.txt&#34;
</span><span class="cp">#define MOB_PATH         &#34;./mob.txt&#34;
</span><span class="cp">#define CATEGORIES_PATH &#34;./categories.txt&#34;
</span><span class="cp">#define BLOG_SRC &#34;./BlogPath.txt&#34;
</span><span class="cp"></span><span class="n">std</span><span class="o">::</span><span class="n">filesystem</span><span class="o">::</span><span class="n">path</span> <span class="n">POSTS_PATH</span><span class="p">;</span><span class="c1">//用于获取post_path
</span><span class="c1"></span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="c1">//TODO 建立枚举映射
</span><span class="c1"></span><span class="k">enum</span> <span class="k">class</span> <span class="nc">SHOW_ARGS</span> <span class="o">:</span> <span class="kt">int</span> <span class="p">{</span>
    <span class="n">EMPTY</span><span class="p">,</span> <span class="n">CATEGORIES</span><span class="p">,</span> <span class="n">IMG</span><span class="p">,</span> <span class="n">BLOG_PATH</span>
<span class="p">};</span>
<span class="c1">//TODO 命令行参数的枚举映射
</span><span class="c1"></span><span class="n">unordered_map</span><span class="o">&lt;</span><span class="n">string</span><span class="p">,</span> <span class="n">SHOW_ARGS</span><span class="o">&gt;</span> <span class="n">MAP</span><span class="p">{</span>
        <span class="p">{</span><span class="s">&#34;-sc&#34;</span><span class="p">,</span> <span class="n">SHOW_ARGS</span><span class="o">::</span><span class="n">CATEGORIES</span><span class="p">},</span>
        <span class="p">{</span><span class="s">&#34;-si&#34;</span><span class="p">,</span> <span class="n">SHOW_ARGS</span><span class="o">::</span><span class="n">IMG</span><span class="p">},</span>
        <span class="p">{</span><span class="s">&#34;-sp&#34;</span><span class="p">,</span> <span class="n">SHOW_ARGS</span><span class="o">::</span><span class="n">BLOG_PATH</span><span class="p">}</span>
<span class="p">};</span>

<span class="c1">//TODO 封装文件读取类
</span><span class="c1"></span><span class="k">class</span> <span class="nc">FileReader</span> <span class="p">{</span>
    <span class="n">stringstream</span> <span class="n">in_buf</span><span class="p">;</span>
    <span class="n">ifstream</span> <span class="n">reader</span><span class="p">;</span>
<span class="k">public</span><span class="o">:</span>
    <span class="n">FileReader</span><span class="p">()</span> <span class="o">=</span> <span class="k">default</span><span class="p">;</span>

    <span class="n">FileReader</span><span class="p">(</span><span class="k">const</span> <span class="n">FileReader</span> <span class="o">&amp;</span><span class="p">)</span> <span class="o">=</span> <span class="k">delete</span><span class="p">;</span>

    <span class="n">FileReader</span><span class="p">(</span><span class="n">FileReader</span> <span class="o">&amp;&amp;</span><span class="p">)</span> <span class="o">=</span> <span class="k">delete</span><span class="p">;</span>

    <span class="o">~</span><span class="n">FileReader</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">reader</span><span class="p">.</span><span class="n">is_open</span><span class="p">())</span>
            <span class="n">reader</span><span class="p">.</span><span class="n">close</span><span class="p">();</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">open</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span> <span class="o">&amp;</span><span class="n">path</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">reader</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">path</span><span class="p">);</span>
        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">reader</span><span class="p">.</span><span class="n">is_open</span><span class="p">())</span> <span class="p">{</span>
            <span class="n">perror</span><span class="p">(</span><span class="s">&#34;reader open failed&#34;</span><span class="p">);</span>
            <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
        <span class="p">}</span>
        <span class="n">in_buf</span> <span class="o">&lt;&lt;</span> <span class="n">reader</span><span class="p">.</span><span class="n">rdbuf</span><span class="p">();</span>
    <span class="p">}</span>

    <span class="kt">bool</span> <span class="nf">readAll</span><span class="p">(</span><span class="n">string</span> <span class="o">&amp;</span><span class="n">dst</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">in_buf</span><span class="p">.</span><span class="n">good</span><span class="p">())</span>
            <span class="n">dst</span> <span class="o">=</span> <span class="n">in_buf</span><span class="p">.</span><span class="n">str</span><span class="p">();</span>
        <span class="k">else</span>
            <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
        <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">bool</span> <span class="nf">readline</span><span class="p">(</span><span class="n">string</span> <span class="o">&amp;</span><span class="n">dst</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">in_buf</span><span class="p">.</span><span class="n">good</span><span class="p">())</span>
            <span class="n">getline</span><span class="p">(</span><span class="n">in_buf</span><span class="p">,</span> <span class="n">dst</span><span class="p">);</span>
        <span class="k">else</span> <span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
        <span class="k">return</span> <span class="nb">true</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">};</span>

<span class="c1">//TODO 封装文件写入类
</span><span class="c1"></span><span class="k">class</span> <span class="nc">FileWriter</span> <span class="p">{</span>
    <span class="kt">char</span> <span class="o">*</span><span class="n">out_buf</span><span class="p">;</span>
    <span class="n">ofstream</span> <span class="n">writer</span><span class="p">;</span>
    <span class="n">size_t</span> <span class="n">cur_buf_size</span><span class="p">;</span>
    <span class="n">size_t</span> <span class="n">max_buf_size</span><span class="p">;</span>
<span class="k">private</span><span class="o">:</span>
    <span class="kt">void</span> <span class="n">_write</span><span class="p">()</span> <span class="p">{</span>  <span class="c1">//缓冲区写满，写入文件中
</span><span class="c1"></span>        <span class="n">writer</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">out_buf</span><span class="p">,</span> <span class="n">max_buf_size</span><span class="p">);</span>
        <span class="n">cur_buf_size</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="p">}</span>

<span class="k">public</span><span class="o">:</span>
    <span class="n">FileWriter</span><span class="p">()</span> <span class="o">:</span> <span class="n">cur_buf_size</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">max_buf_size</span><span class="p">(</span><span class="mi">512</span><span class="p">),</span> <span class="n">out_buf</span><span class="p">(</span><span class="k">nullptr</span><span class="p">)</span> <span class="p">{};</span>

    <span class="n">FileWriter</span><span class="p">(</span><span class="k">const</span> <span class="n">FileReader</span> <span class="o">&amp;</span><span class="p">)</span> <span class="o">=</span> <span class="k">delete</span><span class="p">;</span>

    <span class="n">FileWriter</span><span class="p">(</span><span class="n">FileReader</span> <span class="o">&amp;&amp;</span><span class="p">)</span> <span class="o">=</span> <span class="k">delete</span><span class="p">;</span>

    <span class="n">FileWriter</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span> <span class="o">&amp;</span><span class="n">path</span><span class="p">,</span> <span class="n">ios</span><span class="o">::</span><span class="n">openmode</span> <span class="n">mode</span> <span class="o">=</span> <span class="n">ios</span><span class="o">::</span><span class="n">out</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">writer</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">mode</span><span class="p">);</span>
        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">writer</span><span class="p">.</span><span class="n">is_open</span><span class="p">())</span> <span class="p">{</span>
            <span class="n">perror</span><span class="p">(</span><span class="s">&#34;writer open failed&#34;</span><span class="p">);</span>
            <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
        <span class="p">}</span>
        <span class="n">cur_buf_size</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="n">max_buf_size</span> <span class="o">=</span> <span class="mi">512</span><span class="p">;</span>
        <span class="n">out_buf</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">max_buf_size</span> <span class="o">+</span> <span class="mi">5</span><span class="p">];</span>
    <span class="p">}</span>

    <span class="o">~</span><span class="n">FileWriter</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">cur_buf_size</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">writer</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">out_buf</span><span class="p">,</span> <span class="n">cur_buf_size</span><span class="p">);</span>
            <span class="n">cur_buf_size</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="p">}</span>
        <span class="k">delete</span><span class="p">[]</span> <span class="n">out_buf</span><span class="p">;</span>
        <span class="n">out_buf</span> <span class="o">=</span> <span class="k">nullptr</span><span class="p">;</span>
        <span class="n">writer</span><span class="p">.</span><span class="n">flush</span><span class="p">();</span>
        <span class="n">writer</span><span class="p">.</span><span class="n">close</span><span class="p">();</span>
    <span class="p">}</span>

    <span class="k">static</span> <span class="kt">bool</span> <span class="nf">exist</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span> <span class="o">&amp;</span><span class="n">path</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">access</span><span class="p">(</span><span class="n">path</span><span class="p">.</span><span class="n">c_str</span><span class="p">(),</span> <span class="n">F_OK</span><span class="p">)</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">open</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span> <span class="o">&amp;</span><span class="n">path</span><span class="p">,</span> <span class="n">ios</span><span class="o">::</span><span class="n">openmode</span> <span class="n">mode</span> <span class="o">=</span> <span class="n">ios</span><span class="o">::</span><span class="n">out</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">writer</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">mode</span><span class="p">);</span>
        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">writer</span><span class="p">.</span><span class="n">is_open</span><span class="p">())</span> <span class="p">{</span>
            <span class="n">perror</span><span class="p">(</span><span class="s">&#34;writer open failed&#34;</span><span class="p">);</span>
            <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
        <span class="p">}</span>
        <span class="n">out_buf</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">char</span><span class="p">[</span><span class="n">max_buf_size</span> <span class="o">+</span> <span class="mi">5</span><span class="p">];</span>
    <span class="p">}</span>

    <span class="kt">void</span> <span class="nf">write</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span> <span class="o">&amp;</span><span class="n">src</span><span class="p">)</span> <span class="p">{</span><span class="c1">//TODO 缓冲机制的重要组成
</span><span class="c1"></span>        <span class="k">if</span> <span class="p">(</span><span class="n">writer</span><span class="p">.</span><span class="n">is_open</span><span class="p">())</span> <span class="p">{</span><span class="c1">//只有在open文件后才能写入
</span><span class="c1"></span>            <span class="k">if</span> <span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">empty</span><span class="p">())</span> <span class="k">return</span><span class="p">;</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">cur_buf_size</span> <span class="o">==</span> <span class="n">max_buf_size</span><span class="p">)</span>
                <span class="n">_write</span><span class="p">();</span>
            <span class="n">size_t</span> <span class="n">psize</span> <span class="o">=</span> <span class="n">src</span><span class="p">.</span><span class="n">size</span><span class="p">()</span> <span class="o">+</span> <span class="n">cur_buf_size</span><span class="p">;</span><span class="c1">//如果全盘写入缓冲区后，缓冲区需要的大小
</span><span class="c1"></span>            <span class="kt">int</span> <span class="n">startp</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">maxLen</span><span class="p">;</span>
            <span class="k">while</span> <span class="p">(</span><span class="n">psize</span> <span class="o">&gt;</span> <span class="n">max_buf_size</span><span class="p">)</span> <span class="p">{</span>  <span class="c1">//当这次写入缓冲区的数据量大于缓冲区的大小，则进行不断写满更新操作
</span><span class="c1"></span>                <span class="n">maxLen</span> <span class="o">=</span> <span class="n">max_buf_size</span> <span class="o">-</span> <span class="n">cur_buf_size</span><span class="p">;</span>
                <span class="n">copy</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">begin</span><span class="p">()</span> <span class="o">+</span> <span class="n">startp</span><span class="p">,</span> <span class="n">src</span><span class="p">.</span><span class="n">begin</span><span class="p">()</span> <span class="o">+</span> <span class="n">startp</span> <span class="o">+</span> <span class="n">maxLen</span><span class="p">,</span> <span class="n">out_buf</span> <span class="o">+</span> <span class="n">cur_buf_size</span><span class="p">);</span><span class="c1">//copy到满状态，再来一次write
</span><span class="c1"></span>                <span class="n">_write</span><span class="p">();</span>
                <span class="n">startp</span> <span class="o">+=</span> <span class="n">maxLen</span><span class="p">;</span>
                <span class="n">psize</span> <span class="o">-=</span> <span class="n">max_buf_size</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="c1">//如果写入数据不超出缓冲区大小，则直接写入
</span><span class="c1"></span>            <span class="n">copy</span><span class="p">(</span><span class="n">src</span><span class="p">.</span><span class="n">begin</span><span class="p">()</span> <span class="o">+</span> <span class="n">startp</span><span class="p">,</span> <span class="n">src</span><span class="p">.</span><span class="n">end</span><span class="p">(),</span> <span class="n">out_buf</span> <span class="o">+</span> <span class="n">cur_buf_size</span><span class="p">);</span>
            <span class="n">cur_buf_size</span> <span class="o">+=</span> <span class="n">src</span><span class="p">.</span><span class="n">size</span><span class="p">()</span> <span class="o">-</span> <span class="n">startp</span><span class="p">;</span>
        <span class="p">}</span>
    <span class="p">}</span>

    <span class="n">FileWriter</span> <span class="o">&amp;</span><span class="n">append</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span> <span class="o">&amp;</span><span class="n">src</span><span class="p">)</span> <span class="p">{</span><span class="c1">//TODO 和write没区别，只是支持链式调用
</span><span class="c1"></span>        <span class="n">write</span><span class="p">(</span><span class="n">src</span><span class="p">);</span>
        <span class="k">return</span> <span class="o">*</span><span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">};</span>


<span class="c1">//TODO 整个项目需要操作的变量（很不推荐用全局变量，我就是因为这玩意就导致了bug）
</span><span class="c1"></span><span class="n">FileReader</span> <span class="n">readImg</span><span class="p">,</span> <span class="n">readText</span><span class="p">,</span> <span class="n">readCategories</span><span class="p">;</span><span class="c1">//用于文件io的变量
</span><span class="c1"></span><span class="n">FileWriter</span> <span class="n">appendCategories</span><span class="p">,</span> <span class="n">fileWriter</span><span class="p">;</span>
<span class="n">vector</span><span class="o">&lt;</span><span class="n">string</span><span class="o">&gt;</span> <span class="n">imgs</span><span class="p">,</span> <span class="n">categories</span><span class="p">;</span>         <span class="c1">//用于存下磁盘到内存的数据，根据名字判断存的啥
</span><span class="c1"></span><span class="n">time_t</span> <span class="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="p">(</span><span class="nb">NULL</span><span class="p">);</span>


<span class="c1">//TODO 打开typora软件
</span><span class="c1"></span><span class="kt">void</span> <span class="nf">open_exe_from_path</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">path</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">WinExec</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">SW_SHOWNORMAL</span><span class="p">);</span>
    <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&#34;open your custom editor successfully!&#34;</span> <span class="o">&lt;&lt;</span> <span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>

<span class="c1">//TODO 打印内容
</span><span class="c1"></span><span class="kt">void</span> <span class="nf">show</span><span class="p">(</span><span class="n">vector</span><span class="o">&lt;</span><span class="n">string</span><span class="o">&gt;</span> <span class="o">&amp;</span><span class="n">src</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">for</span> <span class="p">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">src</span><span class="p">.</span><span class="n">size</span><span class="p">();</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">src</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">empty</span><span class="p">())</span>
            <span class="n">printf</span><span class="p">(</span><span class="s">&#34;%d: %s</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">src</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">c_str</span><span class="p">());</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="c1">//TODO 替换string的内容
</span><span class="c1"></span><span class="kt">void</span> <span class="nf">to_replace</span><span class="p">(</span><span class="n">string</span> <span class="o">&amp;</span><span class="n">s</span><span class="p">,</span> <span class="k">const</span> <span class="n">string</span> <span class="o">&amp;</span><span class="n">target</span><span class="p">,</span> <span class="k">const</span> <span class="n">string</span> <span class="o">&amp;</span><span class="n">replacement</span><span class="p">)</span> <span class="p">{</span>
    <span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">find_ret</span><span class="p">;</span>
    <span class="kt">int</span> <span class="n">tar_len</span> <span class="o">=</span> <span class="n">target</span><span class="p">.</span><span class="n">size</span><span class="p">();</span>
    <span class="k">while</span> <span class="p">((</span><span class="n">find_ret</span> <span class="o">=</span> <span class="n">s</span><span class="p">.</span><span class="n">find</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">i</span><span class="p">))</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
        <span class="n">s</span><span class="p">.</span><span class="n">replace</span><span class="p">(</span><span class="n">find_ret</span><span class="p">,</span> <span class="n">tar_len</span><span class="p">,</span> <span class="n">replacement</span><span class="p">);</span>
        <span class="n">i</span> <span class="o">=</span> <span class="n">find_ret</span><span class="p">;</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="c1">//TODO 打印出错的信息，并退出程序
</span><span class="c1"></span><span class="kt">void</span> <span class="nf">exit_print</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">content</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">printf</span><span class="p">(</span><span class="s">&#34;running failed: %s</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">,</span> <span class="n">content</span><span class="p">);</span>
    <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="p">}</span>

<span class="c1">//TODO 得到当前的时间
</span><span class="c1"></span><span class="n">string</span> <span class="nf">get_cur_time</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">tm</span> <span class="o">*</span><span class="n">tm_t</span> <span class="o">=</span> <span class="n">localtime</span><span class="p">(</span><span class="o">&amp;</span><span class="n">now</span><span class="p">);</span>
    <span class="kt">char</span> <span class="n">c_time</span><span class="p">[</span><span class="mi">50</span><span class="p">];</span>
    <span class="n">sprintf</span><span class="p">(</span><span class="n">c_time</span><span class="p">,</span> <span class="s">&#34;%04d-%02d-%02d&#34;</span><span class="p">,</span>
            <span class="n">tm_t</span><span class="o">-&gt;</span><span class="n">tm_year</span> <span class="o">+</span> <span class="mi">1900</span><span class="p">,</span>
            <span class="n">tm_t</span><span class="o">-&gt;</span><span class="n">tm_mon</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span>
            <span class="n">tm_t</span><span class="o">-&gt;</span><span class="n">tm_mday</span><span class="p">);</span>
    <span class="k">return</span> <span class="n">string</span><span class="p">(</span><span class="n">c_time</span><span class="p">);</span>
<span class="p">}</span>


<span class="c1">//TODO 基本的初始化数据
</span><span class="c1"></span><span class="kt">void</span> <span class="nf">InitInputFileInfo</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">readImg</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">IMGS_PATH</span><span class="p">);</span>
    <span class="n">readText</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">MOB_PATH</span><span class="p">);</span>
    <span class="n">readCategories</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">CATEGORIES_PATH</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">InitOutputFileInfo</span><span class="p">(</span><span class="k">const</span> <span class="n">string</span> <span class="o">&amp;</span><span class="n">targetPath</span><span class="p">)</span> <span class="p">{</span>
    <span class="n">fileWriter</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">targetPath</span><span class="p">);</span>
    <span class="n">appendCategories</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">CATEGORIES_PATH</span><span class="p">,</span> <span class="n">ios</span><span class="o">::</span><span class="n">app</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">InitImgs</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">string</span> <span class="n">tmp</span><span class="p">;</span>
    <span class="k">while</span> <span class="p">(</span><span class="n">readImg</span><span class="p">.</span><span class="n">readline</span><span class="p">(</span><span class="n">tmp</span><span class="p">))</span> <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">tmp</span><span class="p">.</span><span class="n">empty</span><span class="p">())</span>
            <span class="n">imgs</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">tmp</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="c1">//todo 经过洗牌算法把数组里面的内容打乱
</span><span class="c1"></span>    <span class="n">shuffle</span><span class="p">(</span><span class="n">imgs</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span> <span class="n">imgs</span><span class="p">.</span><span class="n">end</span><span class="p">(),</span> <span class="n">std</span><span class="o">::</span><span class="n">default_random_engine</span><span class="p">(</span><span class="n">now</span><span class="p">));</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">InitCategories</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">string</span> <span class="n">tmp</span><span class="p">;</span>
    <span class="k">while</span> <span class="p">(</span><span class="n">readCategories</span><span class="p">.</span><span class="n">readline</span><span class="p">(</span><span class="n">tmp</span><span class="p">))</span> <span class="p">{</span>
        <span class="n">categories</span><span class="p">.</span><span class="n">push_back</span><span class="p">(</span><span class="n">tmp</span><span class="p">);</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">InitPostPath</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">FileReader</span> <span class="n">fd</span><span class="p">;</span>
    <span class="n">fd</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">BLOG_SRC</span><span class="p">);</span>
    <span class="n">string</span> <span class="n">pth</span><span class="p">;</span>
    <span class="n">fd</span><span class="p">.</span><span class="n">readline</span><span class="p">(</span><span class="n">pth</span><span class="p">);</span>
    <span class="n">POSTS_PATH</span> <span class="o">=</span> <span class="n">pth</span><span class="p">;</span>
<span class="p">}</span>

<span class="c1">//TODO 处理三个参数的情况
</span><span class="c1"></span><span class="kt">void</span> <span class="nf">solve</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">arg1</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">arg2</span><span class="p">)</span> <span class="p">{</span>
    <span class="c1">//todo 初始化io逻辑
</span><span class="c1"></span>    <span class="n">InitInputFileInfo</span><span class="p">();</span>
    <span class="n">InitImgs</span><span class="p">();</span>
    <span class="n">InitCategories</span><span class="p">();</span>
    <span class="n">string</span> <span class="n">text</span><span class="p">;</span>
    <span class="n">string</span> <span class="n">category</span><span class="p">;</span>
    <span class="n">InitPostPath</span><span class="p">();</span>
    <span class="n">POSTS_PATH</span> <span class="o">/=</span> <span class="s">&#34;content&#34;</span><span class="p">;</span>
    <span class="n">POSTS_PATH</span> <span class="o">/=</span> <span class="s">&#34;posts&#34;</span><span class="p">;</span>
    <span class="n">POSTS_PATH</span> <span class="o">/=</span> <span class="n">string</span><span class="p">(</span><span class="n">arg1</span><span class="p">)</span> <span class="o">+</span> <span class="s">&#34;.md&#34;</span><span class="p">;</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">filesystem</span><span class="o">::</span><span class="n">exists</span><span class="p">(</span><span class="n">POSTS_PATH</span><span class="p">))</span>
        <span class="n">exit_print</span><span class="p">(</span><span class="s">&#34;file exist!&#34;</span><span class="p">);</span>
    <span class="n">InitOutputFileInfo</span><span class="p">(</span><span class="n">POSTS_PATH</span><span class="p">.</span><span class="n">string</span><span class="p">());</span>

    <span class="c1">//todo 替换文本
</span><span class="c1"></span>    <span class="n">srand</span><span class="p">(</span><span class="n">now</span><span class="p">);</span>                         <span class="c1">//以当前时间作为种子重新播种
</span><span class="c1"></span>    <span class="kt">int</span> <span class="n">randomIndex</span> <span class="o">=</span> <span class="n">rand</span><span class="p">()</span> <span class="o">%</span> <span class="n">imgs</span><span class="p">.</span><span class="n">size</span><span class="p">();</span><span class="c1">//随机选择一张图片
</span><span class="c1"></span>    <span class="n">readText</span><span class="p">.</span><span class="n">readAll</span><span class="p">(</span><span class="n">text</span><span class="p">);</span>
    <span class="n">to_replace</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="s">&#34;%s&#34;</span><span class="p">,</span> <span class="n">arg1</span><span class="p">);</span><span class="c1">//更换文章名字为标题名称
</span><span class="c1"></span>    <span class="n">to_replace</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="s">&#34;%T&#34;</span><span class="p">,</span> <span class="n">imgs</span><span class="p">[</span><span class="n">randomIndex</span><span class="p">]);</span><span class="c1">//将图片内容进行替换
</span><span class="c1"></span>    <span class="n">to_replace</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="s">&#34;%D&#34;</span><span class="p">,</span> <span class="n">get_cur_time</span><span class="p">());</span>   <span class="c1">//将当前日期进行替换
</span><span class="c1"></span>    <span class="c1">//根据arg2来选择替换的分类内容
</span><span class="c1"></span>    <span class="k">if</span> <span class="p">(</span><span class="n">to_string</span><span class="p">(</span><span class="n">atoi</span><span class="p">(</span><span class="n">arg2</span><span class="p">))</span> <span class="o">==</span> <span class="n">arg2</span><span class="p">)</span> <span class="p">{</span><span class="c1">//判断arg2传递的是否是数字
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">index</span> <span class="o">=</span> <span class="n">atoi</span><span class="p">(</span><span class="n">arg2</span><span class="p">);</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">index</span> <span class="o">&lt;</span> <span class="n">categories</span><span class="p">.</span><span class="n">size</span><span class="p">()</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="p">{</span><span class="c1">//数字合法选择对应下标的分类
</span><span class="c1"></span>            <span class="n">category</span> <span class="o">=</span> <span class="n">categories</span><span class="p">[</span><span class="n">index</span><span class="p">];</span>
        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span><span class="c1">//数字不合法，退出程序
</span><span class="c1"></span>            <span class="n">exit_print</span><span class="p">(</span><span class="s">&#34;number not allowed&#34;</span><span class="p">);</span>
        <span class="p">}</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span><span class="c1">//不是数字，则说明创建了新的分类
</span><span class="c1"></span>        <span class="n">category</span> <span class="o">=</span> <span class="n">arg2</span><span class="p">;</span>
        <span class="n">appendCategories</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">string</span><span class="p">(</span><span class="n">arg2</span><span class="p">)</span> <span class="o">+</span> <span class="s">&#34;</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="n">to_replace</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="s">&#34;#&#34;</span><span class="p">,</span> <span class="n">category</span><span class="p">);</span>
    <span class="c1">//todo 最后再将数据写入磁盘
</span><span class="c1"></span>    <span class="n">fileWriter</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">text</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="k">const</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> <span class="p">{</span>
    <span class="n">system</span><span class="p">(</span><span class="s">&#34;chcp 65001&#34;</span><span class="p">);</span>
    <span class="n">SHOW_ARGS</span> <span class="n">state</span><span class="p">;</span><span class="c1">//由于switch语句的第一层不能定义临时变量
</span><span class="c1"></span>    <span class="k">switch</span> <span class="p">(</span><span class="n">argc</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">case</span> <span class="mi">2</span><span class="o">:</span><span class="c1">//todo 外界传来的字符串实际上不是很重要，主要是可以根据这个字符串确定枚举状态，然后再进行不同内容的show操作
</span><span class="c1"></span>            <span class="n">state</span> <span class="o">=</span> <span class="n">MAP</span><span class="p">[</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]];</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">state</span> <span class="o">==</span> <span class="n">SHOW_ARGS</span><span class="o">::</span><span class="n">EMPTY</span><span class="p">)</span> <span class="p">{</span><span class="c1">//1.哈希表中无该字符串
</span><span class="c1"></span>                <span class="n">fputs</span><span class="p">(</span><span class="s">&#34;args error,may be you should get something below:</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">,</span> <span class="n">stderr</span><span class="p">);</span>
                <span class="k">for</span> <span class="p">(</span><span class="k">auto</span><span class="p">[</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">]</span><span class="o">:</span><span class="n">MAP</span><span class="p">)</span> <span class="p">{</span><span class="c1">//显示参数提示
</span><span class="c1"></span>                    <span class="k">if</span> <span class="p">(</span><span class="n">v</span> <span class="o">==</span> <span class="n">SHOW_ARGS</span><span class="o">::</span><span class="n">EMPTY</span><span class="p">)</span><span class="k">continue</span><span class="p">;</span><span class="c1">//把上面获得值的时候创建的对象给跳过
</span><span class="c1"></span>                    <span class="n">fputs</span><span class="p">((</span><span class="n">k</span> <span class="o">+</span> <span class="sc">&#39;\n&#39;</span><span class="p">).</span><span class="n">c_str</span><span class="p">(),</span> <span class="n">stderr</span><span class="p">);</span>
                <span class="p">}</span>
                <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
            <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">state</span> <span class="o">==</span> <span class="n">SHOW_ARGS</span><span class="o">::</span><span class="n">CATEGORIES</span><span class="p">)</span> <span class="p">{</span><span class="c1">//2.显示分类信息
</span><span class="c1"></span>                <span class="n">InitInputFileInfo</span><span class="p">();</span>
                <span class="n">InitCategories</span><span class="p">();</span>
                <span class="n">show</span><span class="p">(</span><span class="n">categories</span><span class="p">);</span>
            <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">state</span> <span class="o">==</span> <span class="n">SHOW_ARGS</span><span class="o">::</span><span class="n">IMG</span><span class="p">)</span> <span class="p">{</span><span class="c1">//3.显示图片的链接
</span><span class="c1"></span>                <span class="n">InitInputFileInfo</span><span class="p">();</span>
                <span class="n">InitImgs</span><span class="p">();</span>
                <span class="n">show</span><span class="p">(</span><span class="n">imgs</span><span class="p">);</span>
            <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">state</span> <span class="o">==</span> <span class="n">SHOW_ARGS</span><span class="o">::</span><span class="n">BLOG_PATH</span><span class="p">)</span> <span class="p">{</span><span class="c1">//4.显示博客地址
</span><span class="c1"></span>                <span class="n">InitPostPath</span><span class="p">();</span>
                <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">POSTS_PATH</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39;\n&#39;</span><span class="p">;</span>
            <span class="p">}</span>
            <span class="k">return</span> <span class="mi">0</span><span class="p">;</span><span class="c1">//仅仅展示数据就退出
</span><span class="c1"></span>        <span class="k">case</span> <span class="mi">3</span><span class="o">:</span>
            <span class="n">solve</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">]);</span>
            <span class="k">break</span><span class="p">;</span>
        <span class="k">default</span><span class="o">:</span>
            <span class="n">printf</span><span class="p">(</span><span class="s">&#34;Usage :</span><span class="se">\n</span><span class="s">%s [title name] [category name]</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
            <span class="n">printf</span><span class="p">(</span><span class="s">&#34;%s [-op]</span><span class="se">\n</span><span class="s">such as -s to show what category number can choose.</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
            <span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="n">ifstream</span> <span class="n">reader</span><span class="p">;</span><span class="c1">//读取编辑器的地址并打开
</span><span class="c1"></span>    <span class="n">reader</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s">&#34;./ed_Path.txt&#34;</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">reader</span><span class="p">.</span><span class="n">is_open</span><span class="p">())</span> <span class="p">{</span>
        <span class="n">exit_print</span><span class="p">(</span><span class="s">&#34;file reader failed in read editorPath&#34;</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="n">string</span> <span class="n">str</span><span class="p">;</span>
    <span class="n">reader</span> <span class="o">&gt;&gt;</span> <span class="n">str</span><span class="p">;</span>
    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">str</span><span class="p">.</span><span class="n">empty</span><span class="p">())</span>
        <span class="n">open_exe_from_path</span><span class="p">(</span><span class="n">str</span><span class="p">.</span><span class="n">c_str</span><span class="p">());</span>
    <span class="k">else</span> <span class="p">{</span>   <span class="c1">//如果文件编辑器路径未设置，则默认用vscode打开目录
</span><span class="c1"></span>        <span class="n">string</span> <span class="n">cmd</span> <span class="o">=</span> <span class="s">&#34;code &#34;</span> <span class="o">+</span> <span class="n">POSTS_PATH</span><span class="p">.</span><span class="n">string</span><span class="p">();</span>
        <span class="n">system</span><span class="p">(</span><span class="n">cmd</span><span class="p">.</span><span class="n">c_str</span><span class="p">());</span>
        <span class="n">printf</span><span class="p">(</span><span class="s">&#34;open vscode successfully!</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="n">reader</span><span class="p">.</span><span class="n">close</span><span class="p">();</span>
    <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&#34;finish yet!&#34;</span> <span class="o">&lt;&lt;</span> <span class="n">endl</span><span class="p">;</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div><div class="post-footer" id="post-footer">
    <div class="post-info"><div class="post-info-tag"><span><a href="/tags/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/">Hugo博客图形化写作工具</a>
                </span></div><div class="post-info-line"><div class="post-info-mod">
                <span>更新于 2022-02-12</span>
            </div><div class="post-info-mod"></div>
        </div><div class="post-info-share">
            <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://acking-you.github.io/posts/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/" data-title="Hugo博客图形化写作工具" data-hashtags="Hugo博客图形化写作工具"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://acking-you.github.io/posts/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/" data-hashtag="Hugo博客图形化写作工具"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://acking-you.github.io/posts/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/" data-title="Hugo博客图形化写作工具" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://acking-you.github.io/posts/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/" data-title="Hugo博客图形化写作工具"><i class="fab fa-line fa-fw"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://acking-you.github.io/posts/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/" data-title="Hugo博客图形化写作工具" data-image="https://img-blog.csdnimg.cn/img_convert/5bc78a387fa03b5039b9bca28aea1b14.png#pic_center"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://acking-you.github.io/posts/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/" data-title="Hugo博客图形化写作工具" data-description="Hugo博客图形化写作工具"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://acking-you.github.io/posts/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/" data-title="Hugo博客图形化写作工具" data-description="Hugo博客图形化写作工具"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://acking-you.github.io/posts/hugo%E5%8D%9A%E5%AE%A2%E5%9B%BE%E5%BD%A2%E5%8C%96%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7/" data-title="Hugo博客图形化写作工具"><i class="fab fa-evernote fa-fw"></i></a></span>
        </div></div><div class="post-nav"><a href="/posts/leetcode%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%981020%E9%A3%9E%E5%9C%B0%E7%9A%84%E6%95%B0%E9%87%8F/" class="prev" rel="prev" title="并查集/dfs解决——leetcode每日一题——1020飞地的数量"><i class="fas fa-angle-left fa-fw"></i>Previous Post</a>
            <a href="/posts/%E7%89%9B%E5%AE%A2-wyh%E7%9A%84%E7%89%A9%E5%93%81%E9%80%9A%E8%BF%87%E9%AA%8C%E8%AF%81%E5%BE%97%E5%87%BA%E4%BA%8C%E5%88%86%E7%9A%84%E6%90%9C%E7%B4%A2%E5%8C%BA%E9%97%B4/" class="next" rel="next" title="牛客-wyh的物品——通过验证得出二分的搜索区间">Next Post<i class="fas fa-angle-right fa-fw"></i></a></div></div>
</div></article></div>
            </main>
            <footer class="footer"><div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.86.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/khusika/FeelIt" target="_blank" rel="noopener noreffer" title="FeelIt 1.0.1"><i class="fas fa-hand-holding-heart fa-fw"></i> FeelIt</a>
        </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2023</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/"></a></span></div>
</div>
</footer>
        </div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-chevron-up fa-fw"></i>
            </a></div><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script src="/lib/autocomplete/autocomplete.min.js"></script><script src="/lib/lunr/lunr.min.js"></script><script src="/lib/lunr/lunr.stemmer.support.min.js"></script><script src="/lib/lunr/lunr.zh.min.js"></script><script src="/lib/lazysizes/lazysizes.min.js"></script><script src="/lib/clipboard/clipboard.min.js"></script><script src="/lib/sharer/sharer.min.js"></script><script src="/lib/katex/katex.min.js"></script><script src="/lib/katex/auto-render.min.js"></script><script src="/lib/katex/copy-tex.min.js"></script><script src="/lib/katex/mhchem.min.js"></script><script>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":200},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":100,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script src="/js/theme.min.js"></script></body></html>
